package zack.project.domain.strategy.service.rule.chain.impl;

import zack.project.domain.strategy.adapter.repository.IStrategyRepository;
import zack.project.domain.strategy.service.armory.IStrategyDispatch;
import zack.project.domain.strategy.service.rule.chain.AbstractLogicChain;
import zack.project.domain.strategy.service.rule.chain.factory.DefaultChainFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author A1793
 */
@Slf4j
@Component("rule_default")
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)

public class DefaultLogicChain extends AbstractLogicChain {

    @Resource
    private IStrategyRepository repository;
    @Resource
    private IStrategyDispatch strategyDispatch;

    @Override
    protected String ruleModels() {
        return DefaultChainFactory.LogicModel.RULE_DEFAULT.getCode();
    }

    /**
     * 默认节点直接进行随机抽奖
     *
     * @param userId
     * @param strategyId
     * @return
     */
    @Override
    public DefaultChainFactory.StrategyAwardVO logic(String userId, Long strategyId) {

        Integer awardId = strategyDispatch.getRandomAwardId(strategyId);
        log.info("抽奖责任链-默认处理 userId:{} strategyId:{} ruleModel:{} awardId:{}", userId, strategyId,
                ruleModels(),
                awardId);

        return DefaultChainFactory.StrategyAwardVO
                .builder().awardId(awardId)
                .logicModel(ruleModels())
                .awardRuleValue(" ")
                .build();
    }


}
